package com.guijq.design.singleton;

/**
 * @author yangjf
 * @version 0.1.0
 * @time 2018/9/12/012
 */
public class Singleton3 {
    private volatile static Singleton3 uniqueInstance;

    private Singleton3() {
    }

    /**
     *
     * @return
     *
     *  双重检查加锁
     *
     *  volatile 关键字确保 可见性
     */
    public static Singleton3 getInstance() {
        if (uniqueInstance == null) {
            synchronized (Singleton3.class) {
                if (uniqueInstance == null) {
                    uniqueInstance = new Singleton3();
                }
            }
            uniqueInstance = new Singleton3();
        }
        return uniqueInstance;
    }
}
